package com.guanyu.u2cache.elect;

import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author zhouyunjian
 * @date 2023/11/24 14:48
 * 选举master逻辑：
 * 1、一级缓存自己为master
 * 2、二级缓存需要选举master
 **/
@Component
public abstract class ElectMaster {

    protected AtomicBoolean isMaster = new AtomicBoolean(true);


    /**
     * 默认本机是master机制
     *
     * @return
     */
    public boolean isMaster() {
        return this.isMaster.get();
    }

    protected abstract void electMaster();
}
